﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Admin.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<%@ Import Namespace="WebHoiChoMuaBan.Controllers.Helpers" %>
<%@ Import Namespace="WebHoiChoMuaBan.Controllers" %>
<%@ Import Namespace="WebHoiChoMuaBan.Models" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    RightManagement
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <form action="<%= Url.Action("AddGroupRight","AdminManagement") %>" method="post"
    enctype="multipart/form-data">
    <div id="left" style="float: left; width: 30%">
        <%
            WebHoiChoMuaBan.Models.Group grp = (WebHoiChoMuaBan.Models.Group)ViewData["Group"];
            
        %>
        <input type="text" name="grpID" id="grpID" class="hidden" value="<%=grp.GroupID %>" />
        <table>
            <tr>
                <td>
                </td>
                <td>
                    Tên nhóm
                </td>
            </tr>
            <tr>
                <td>
                </td>
                <td>
                    <%=grp.GroupName %>
                </td>
            </tr>
        </table>
    </div>
    <%List<Right> right = (List<Right>)ViewData["lstRight"]; %>
    <div id="right" style="float: right; width: 70%">
        <div id="right-left" style="float: left; width: 70%">
            <table id="tableRight">
                <tr>
                    <td>
                    </td>
                    <td>
                        Tên quyền
                    </td>
                    <td>
                        Mô tả
                    </td>
                </tr>
                <%
                    foreach (Right rht in right)
                    {
                        if (rht.RightName.Equals("1"))
                        {
                %>
                <tr>
                    <td>
                        <% List<Group_Right> lstGR = new AdminHelper().getAllGroupRightByGroupId(grp.GroupID);
                           List<int> lstInt = new List<int>();
                           foreach (Group_Right gr in lstGR)
                           {
                               lstInt.Add(gr.RightID);
                           }
                           if (lstInt.Contains(rht.RightID))
                           {
                        %>
                        <input type="checkbox" checked="checked" onclick="RightclearAllRadios(this)" value="-1" />
                        <%
}
                           else
                           {
                        %>
                        <input type="checkbox" onclick="RightclearAllRadios(this)" value="-1" />
                        <%
} %>
                    </td>
                    <td>
                        <%=rht.RightName%>
                    </td>
                    <td>
                        <%=rht.Description%>
                    </td>
                </tr>
                <%}
                        else
                        {
                            
                %>
                <tr>
                    <td>
                        <% List<Group_Right> lstGR = new AdminHelper().getAllGroupRightByGroupId(grp.GroupID);
                           List<int> lstInt = new List<int>();
                           foreach (Group_Right gr in lstGR)
                           {
                               lstInt.Add(gr.RightID);
                           }
                           if (lstInt.Contains(rht.RightID))
                           {
                        %>
                        <input type="checkbox" checked="checked" value="<%=rht.RightID %>" onclick="ChildRightclearAllRadios(this)" />
                        <%
}
                           else
                           {
                        %>
                        <input type="checkbox" value="<%=rht.RightID %>" onclick="ChildRightclearAllRadios(this)" />
                        <%
} %>
                    </td>
                    <td>
                        <%=rht.RightName%>
                    </td>
                    <td>
                        <%=rht.Description%>
                    </td>
                    <td>
                        <%
                            if (rht.RightName.Equals("5"))
                            {
                                try
                                {
                                    int? templateId = new AdminHelper().getTemplateID(grp.GroupID, rht.RightID); %>
                        <select name="<%=rht.RightID %>_Select">
                            <%if (templateId == null)
                              {
                            %><option value="-1" selected="selected">Tất cả</option>
                            <option value="2">Real Estate</option>
                            <option value="3">Product</option>
                            <option value="4">New</option>
                            <%
                            }
                              else
                              {
                                  if (templateId == 2)
                                  {
                            %>
                            <option value="-1">Tất cả</option>
                            <option value="2" selected="selected">Real Estate</option>
                            <option value="3">Product</option>
                            <option value="4">New</option>
                            <%
                            }
                                  else
                                  {
                                      if (templateId == 3)
                                      {
                            %>
                            <option value="-1">Tất cả</option>
                            <option value="2">Real Estate</option>
                            <option value="3" selected="selected">Product</option>
                            <option value="4">New</option>
                            <%
                            }
                                      else
                                      {
                            %>
                            <option value="-1">Tất cả</option>
                            <option value="2">Real Estate</option>
                            <option value="3">Product</option>
                            <option value="4" selected="selected">New</option>
                            <%
                            }
                                  }
                              }
                                }
                                catch
                                {
                            %>
                            <select name="<%=rht.RightID %>_Select">
                                <option value="-1">Tất cả</option>
                                <option value="2">Real Estate</option>
                                <option value="3">Product</option>
                                <option value="4">New</option>
                            </select>
                            <%
                            }
                            }
                            %>
                        </select>
                    </td>
                </tr>
                <%
                    }
                    }
                %>
            </table>
        </div>
        <%--    <div id="right-right">
            <%
                List<Template> template = (List<Template>)ViewData["lstTemplate"];
            %>
            <table id="tableTemplate">
                <tr>
                    <td>
                    </td>
                    <td>
                        Phạm vi
                    </td>
                </tr>
                <tr>
                    <td>
                        <input type="checkbox" onclick="TemplateclearAllRadios(this)" value="-1" />
                    </td>
                    <td>
                        Tất cả
                    </td>
                </tr>
                <%
                    foreach (Template tmp in template)
                    {
                        
                %>
                <tr>
                    <td>
                        <input type="checkbox" onclick="ChildTemplateclearAllRadios(this)" value="<%=tmp.TemId %>" />
                    </td>
                    <td>
                        <%=tmp.TemFilePath %>
                    </td>
                </tr>
                <%
                    } %>
            </table>
        </div>--%>
        <div class="clr">
        </div>
    </div>
    <div class="clr">
    </div>
    <center>
        <input type="submit" />
    </center>
    </form>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="HeadHolder" runat="server">
    <script type="text/javascript">
        function TemplateclearAllRadios(obj) {
            var radio = document.getElementById("tableTemplate");
            var input = radio.getElementsByTagName("input");
            for (var i = 1; i < input.length; i++) {
                if (input[i].checked) input[i].checked = false;
            }
            var action;
            if (obj.checked)
                action = 1;
            else
                action = 0;
            $.ajax({
                type: "POST",
                url: "/AdminManagement/StoreTemplate",
                data: "value=" + obj.value + "&action=" + action,
                success: function (result) {
                },
                error: function (req, status, error) {
                    alert("Sorry! We could not receive your feedback at this time.");
                }
            });
        }

        function ChildTemplateclearAllRadios(obj) {
            var radio = document.getElementById("tableTemplate");
            var input = radio.getElementsByTagName("input");
            //for (var i = 0; i < input.length; i++) {
            if (input[0].checked) input[0].checked = false;
            //}

            var action;
            if (obj.checked)
                action = 1;
            else
                action = 0;
            $.ajax({
                type: "POST",
                url: "/AdminManagement/StoreTemplate",
                data: "value=" + obj.value + "&action=" + action,
                success: function (result) {
                },
                error: function (req, status, error) {
                    alert("Sorry! We could not receive your feedback at this time.");
                }
            });
        }

    </script>
    <script type="text/javascript">
        function RightclearAllRadios(obj) {
            var radio = document.getElementById("tableRight");
            var input = radio.getElementsByTagName("input");
            for (var i = 1; i < input.length; i++) {
                if (input[i].checked) input[i].checked = false;
            }

            var action;
            if (obj.checked)
                action = 1;
            else
                action = 0;

            $.ajax({
                type: "POST",
                url: "/AdminManagement/StoreRight",
                data: "value=" + obj.value + "&action=" + action,
                success: function (result) {
                },
                error: function (req, status, error) {
                    alert("Sorry! We could not receive your feedback at this time.");
                }
            });
        }

        function ChildRightclearAllRadios(obj) {

            var radio = document.getElementById("tableRight");
            var input = radio.getElementsByTagName("input");
            //for (var i = 0; i < input.length; i++) {
            if (input[0].checked) input[0].checked = false;
            //}

            var action;
            if (obj.checked)
                action = 1;
            else
                action = 0;

            $.ajax({
                type: "POST",
                url: "/AdminManagement/StoreRight",
                data: "value=" + obj.value + "&action=" + action,
                success: function (result) {
                },
                error: function (req, status, error) {
                    alert("Sorry! We could not receive your feedback at this time.");
                }
            });
        }
    </script>
</asp:Content>
